package service;

import dao.TrainDao;
import model.Train;
import java.util.Date;
import java.util.List;

/**
 * 列车服务类
 */
public class TrainService {
    private TrainDao trainDao = new TrainDao();

    // 添加列车
    public boolean addTrain(Train train) {
        return trainDao.addTrain(train);
    }

    // 获取所有列车信息
    public List<Train> getAllTrains() {
        return trainDao.getAllTrains();
    }

    // 查询列车
    public List<Train> searchTrains(String departure, String destination, Date date) {
        return trainDao.findByDepartureAndDestination(departure, destination, date);
    }

    // 获取列车信息
    public Train getTrainById(int trainId) {
        return trainDao.getById(trainId);
    }

    // 更新列车座位数
    public boolean updateTrainSeats(int trainId, int newAvailableSeats) {
        return trainDao.updateSeats(trainId, newAvailableSeats);
    }
}